//
//  PayResultViewController.m
//  ZiJinLian
//
//  Created by 🐛 on 2017/5/16.
//  Copyright © 2017年 lzy. All rights reserved.
//

#import "PayResultViewController.h"
#import "AllOrderViewController.h"
#import "VowViewController.h"
#import "DealersViewController.h"
#import "MyWishViewController.h"
#import "ShopDetailViewController.h"
#import "AllOrderViewController.h"
#import "OrderDetailViewController.h"
#import "ZJShopCarViewController.h"
@interface PayResultViewController ()

@end

@implementation PayResultViewController
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"icon_back"] style:UIBarButtonItemStyleDone target:self action:@selector(backAction)];
}
-(void)backAction{
    for (UIViewController*view in self.navigationController.viewControllers ) {
        if ([view isKindOfClass:[ShopDetailViewController class]]) {
            [self.navigationController popToViewController:view animated:YES];
        }else if ([view isKindOfClass:[VowViewController class]]){
            [self.navigationController popToViewController:view animated:YES];
        }else if ([view isKindOfClass:[DealersViewController class]]){
            [self.navigationController popToViewController:view animated:YES];
        }else if ([view isKindOfClass:[MyWishViewController class]]){
            [self.navigationController popToViewController:view animated:YES];
        }else if ([view isKindOfClass:[AllOrderViewController class]]){
            [self.navigationController popToViewController:view animated:YES];
        }else if ([view isKindOfClass:[OrderDetailViewController class]]){
            [self.navigationController popToViewController:view animated:YES];
        }else{
            //不确保其他还有遗漏 如有遗漏请手动添加以去除连续pop效果
            //[self.navigationController popViewControllerAnimated:YES];
        }
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title=@"支付结果";
    if (self.result==Succeed) {
        [self SucceedView];
    }else{
        [self FailView];
    }
    // Do any additional setup after loading the view.
}

//成功页面
-(void)SucceedView{
    UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, MainW, MainH)];
    view.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:view];
    UIImageView*headImg=[[UIImageView alloc]init];
    headImg.image=[UIImage imageNamed:@"img_success_monk"];
    [view addSubview:headImg];
    [headImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(100);
        make.centerX.equalTo(view.mas_centerX);
        make.width.equalTo(180);
        make.height.equalTo(210);
    }];
    MYLabel *label=[[MYLabel alloc]init];
    label.text=MyString(@"支付成功");
    label.textColor=button_Red_Color;
    label.textAlignment=1;
    [view addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(headImg.mas_bottom).offset(20);
        make.right.equalTo(0);
        make.width.equalTo(MainW);
        make.height.equalTo(20);
    }];
    UIButton *button=[[UIButton alloc]init];
    [button setTitle:MyString(@"返回首页") forState:UIControlStateNormal];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    button.tag=1;
    [button addTarget:self action:@selector(FinishClick:) forControlEvents:UIControlEventTouchUpInside];
    [button setBackgroundColor:tableBarRedColor];
    [view addSubview:button];
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(label.mas_bottom).offset(20);
        make.left.equalTo(10);
        make.width.equalTo(MainW/2-12.5);
        make.height.equalTo(50);
    }];
    ViewRadius(button, 5);
    UIButton *button2=[[UIButton alloc]init];
    [button2 setTitle:MyString(@"查看订单") forState:UIControlStateNormal];
    [button2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    button2.tag=2;
    [button2 addTarget:self action:@selector(FinishClick:) forControlEvents:UIControlEventTouchUpInside];
    [button2 setBackgroundColor:button_Red_Color];
    [view addSubview:button2];
    [button2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(label.mas_bottom).offset(20);
        make.left.equalTo(button.mas_right).offset(5);
        make.width.equalTo(MainW/2-12.5);
        make.height.equalTo(50);
    }];
    ViewRadius(button2, 5);
    
    
}
//失败页面
-(void)FailView{
    UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, MainW, MainH)];
    view.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:view];
    UIImageView*headImg=[[UIImageView alloc]init];
    headImg.image=[UIImage imageNamed:@"img_fail_monk"];
    [view addSubview:headImg];
    [headImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(100);
        make.centerX.equalTo(view.mas_centerX);
        make.width.equalTo(180);
        make.height.equalTo(210);
    }];
    MYLabel *label=[[MYLabel alloc]init];
    label.textColor=tableBarRedColor;
    label.textAlignment=1;
    label.text=MyString(@"支付失败");
    [view addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(headImg.mas_bottom).offset(20);
        make.right.equalTo(0);
        make.width.equalTo(MainW);
        make.height.equalTo(20);
    }];
    UIButton *button=[[UIButton alloc]init];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    button.tag=3;
    [button addTarget:self action:@selector(FinishClick:) forControlEvents:UIControlEventTouchUpInside];
    [button setBackgroundColor:tableBarRedColor];
    [view addSubview:button];
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(label.mas_bottom).offset(20);
        make.right.equalTo(-10);
        make.width.equalTo(MainW-20);
        make.height.equalTo(50);
    }];
    ViewRadius(button, 5);
    [button setTitle:MyString(@"重新支付") forState:UIControlStateNormal];
}
-(void)FinishClick:(UIButton *)sender{
    switch (sender.tag) {
        case 3:
        {
            [self.navigationController popViewControllerAnimated:YES];
        }
            break;
        case 2:
        {
            
            AllOrderViewController*vc=[[AllOrderViewController alloc]init];
            if (self.IsNear) {
                vc.stype=0;
            }else{
                vc.stype=2;
            }
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 1:
        {
            MianTabBarViewController *tabbar = [[MianTabBarViewController alloc] init];
            [tabbar setSelectedIndex:0];
            [UIApplication sharedApplication].keyWindow.rootViewController = tabbar;
        }
            break;
            
        default:
            break;
    }
    
    
}
@end
